package com.atguigu.daijia.driver.service.impl;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.driver.client.DriverInfoFeignClient;
import com.atguigu.daijia.driver.service.LocationService;
import com.atguigu.daijia.map.client.LocationFeignClient;
import com.atguigu.daijia.model.entity.driver.DriverSet;
import com.atguigu.daijia.model.form.map.SearchNearByDriverForm;
import com.atguigu.daijia.model.form.map.UpdateDriverLocationForm;
import com.atguigu.daijia.model.vo.map.NearByDriverVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationServiceImpl implements LocationService {

@Autowired
LocationFeignClient locationFeignClient;
@Autowired
    DriverInfoFeignClient driverInfoFeignClient;
    @Override
    public Boolean updateDriverLocation(UpdateDriverLocationForm updateDriverLocationForm) {
//        return locationFeignClient.updateDriverLocation(updateDriverLocationForm).getData();
//        开启接单了才能更新司机接单位置
        DriverSet driverSet=driverInfoFeignClient.getDriverSet(updateDriverLocationForm.getDriverId()).getData();
        if (driverSet.getServiceStatus().intValue()==1){
            return locationFeignClient.updateDriverLocation(updateDriverLocationForm).getData();
        }else {
            throw new GuiguException(ResultCodeEnum.NO_START_SERVICE);
        }
    }

    @Override
    public List<NearByDriverVo> searchNearbyDriver(SearchNearByDriverForm searchNearByDriverForm) {
        return locationFeignClient.searchNearbyDriver(searchNearByDriverForm).getData();
    }
}
